#include "src/byte_order.h"
#include <string.h>
#include "src/rdendian.h"

uint16_t get_uint16_from_be_stream(const uint8_t *p) {
    uint16_t n = *(const uint16_t *)p;
    return be16toh(n);
}

uint32_t get_uint32_from_be_stream(const uint8_t *p) {
    uint32_t n = *(const uint32_t *)p;
    return be32toh(n);
}

uint64_t get_uint64_from_be_stream(const uint8_t *p) {
    uint64_t n = *(const uint64_t *)p;
    return be64toh(n);
}

void put_uint16_into_be_stream(uint8_t *buf, uint16_t n) {
    auto x = htobe16(n);
    memcpy(buf, &x, sizeof(uint16_t));
}

void put_uint32_into_be_stream(uint8_t *buf, uint32_t n) {
    auto x = htobe32(n);
    memcpy(buf, &x, sizeof(uint32_t));
}

void put_uint64_into_be_stream(uint8_t *buf, uint64_t n) {
    auto x = htobe64(n);
    memcpy(buf, &x, sizeof(uint64_t));
}
